﻿using B.S.DataBase.MyProject.Domain.RBAC;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using MediatR;
using System.Drawing.Printing;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Menus
{
    public class OnlyMenuNameCommandHandler : IRequestHandler<OnlyMenuNameCommand, APIResult<object>>
    {
        private readonly IBaseRepository<Menu> menuRep;

        public OnlyMenuNameCommandHandler(IBaseRepository<Menu> menuRep)
        {
            this.menuRep = menuRep;
        }

        public Task<APIResult<object>> Handle(OnlyMenuNameCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object> ();
            var list = menuRep.GetAll().Result.Where(x=>x.PId==request.MenuId&&x.MenuName==request.MenuName);
            if (list.Count() > 0)
            {
                result.Code = APIEnum.用户名重复;
                result.Msg=APIEnum.用户名重复.ToString();
                result.data = list.Count();
            }
            else
            {
                result.Code = APIEnum.用户名唯一通过;
                result.Msg = APIEnum.用户名唯一通过.ToString();
                result.data = list.Count();
            }
            return Task.FromResult(result);
        }
    }
}
